﻿<script>
    $(function () {
        $("#ToolBar").AspLinkToolBar();
        $(".H3Panel").BuildPanel({ excludeIDs: ["SystemAclList"] });
        CreateLigerGrid(
            $("#SystemAclList"),
            GetCategoryColumns(),
            $.Controller.SystemAcl.GetSystemAclList,
            true
            );

        $("#divUser").SheetUser({ Editable: true, Visiable: true, Originate: true });

    })
    function GetCategoryColumns() {
        var userName = $.Lang("SystemAcl.UserName");
        var loginName = $.Lang("SystemAcl.LoginName");
        var organization = $.Lang("SystemAcl.Organization");
        var manager = $.Lang("SystemAcl.Administrator");
        var edit = $.Lang("GlobalButton.Edit");
        return [
           { display: "ObjectID", name: "ObjectID", hide: true },
           { display: loginName, name: "LoginName", width: '30%' },
           { display: userName, name: "UserName", width: '30%' },
           { display: organization, name: "Organization", width: '30%' }
        ];
    }
    function AddFun() {
        var userId = $("#divUser").SheetUIManager().GetValue();
        if (!userId) {
            $.H3Dialog.Warn({ content: $.Lang("msgGlobalString.SelectItem") });
            return;
        }
        $.ajax({
            url: $.Controller.SystemAcl.SaveSystemAcl,
            type: 'post',
            dataType: "json",
            data: { id: userId },
            success: function (result) {
                if (result.Success) {
                    $.H3Dialog.Success({ content: $.Lang("SystemAcl.AddSucced") });
                    ReloadGrid();
                } else {
                    if (result.Extend) {
                        $.H3Dialog.Warn({ content: $.format(result.Message,result.Extend) });
                    } else {
                        $.H3Dialog.Warn({ content: $.Lang(result.Message) });
                    }
                }
            }
        });
    }

    function RowEditClick(obj) {
        var title = $.Lang("SystemAcl.EditManager");
        ShowDialog(title, _PORTALROOT_GLOBAL+ "/admin/TabMaster.html?url=SysParam/EditSystemAcl.html&Id=" + obj.id);
    }
    function DeleteFun(obj) {
        var SelectItemName = $.Lang("msgGlobalString.SelectItem");
        var rows = H3GridManager.getSelectedRows();
        if (rows == null || rows.length == 0) {
            $.H3Dialog.Warn({ content: SelectItemName });
            return false;
        }
        var ids = "";
        for (var i = 0; i < rows.length; i++) {
            ids = ids + rows[i].ObjectID + ",";
        }
        if (ConfirmDel(obj)) {
            $.ajax({
                url: $.Controller.SystemAcl.DelSystemAcl,
                type: 'post',
                dataType: "json",
                data: { ids: ids },
                success: function (result) {
                    if (result.Success) {
                        $.H3Dialog.Success({ content: $.Lang("msgGlobalString.DeleteSucced") });
                        ReloadGrid();
                    } else {
                        $.H3Dialog.Warn({ content: $.Lang(result.Message) });
                    }
                }
            });
        }
    };

    //保存系统管理员
    function saveData(obj) {
        var id = obj.Id;
        $.ajax({
            url: $.Controller.SystemAcl.SaveSystemAcl,
            type: "post",
            dataType: "json",
            data: { id: id },
            success: function (result) {
                if (result.Success) {
                    parent.H3DialogManger.Close();
                } else {
                    $.H3Dialog.Warn({ content: $.Lang(result.msg) });
                }
            }
        });
    };

    //重新加载页面数据
    function ReloadGrid() {
        var manager = $("#SystemAclList").ligerGetGridManager();
        manager.reload();
    }
</script>
<div id="ToolBar">
    <!--<a href="#" id="lnkAdd" data-icon="fa fa-plus" onclick="AddFun()" data-lang="GlobalButton.Add">添加</a>-->
    <a onclick="return DeleteFun(this);" id="" data-icon="fa fa-minus" href="javascript:void(0)" data-lang="GlobalButton.Delete">删除</a>
</div>
<div class="H3Panel">
    <table>
        <tr>
            <td data-lang="SystemAcl.NewManager">新管理员</td>
            <td style="width: 250px;">
                <div id="divUser" style="width: 200px;"></div>
            </td>
            <td>
                <a href="#" id="lnkAdd" data-icon="fa fa-plus" onclick="AddFun()" data-lang="GlobalButton.Add">添加</a>
            </td>
        </tr>
    </table>
</div>
<div class="H3Panel">
    <div id="SystemAclList"></div>
</div>